<?php 

class productstoresku  {




	public function insertbatch($parm){
		self::delete($parm);
		foreach($parm['storeId'] as $key=>$value){
			DB::insert("sysproductstoresku",array('productId','specificationId','number','freeze','storeId'))
				->values(array($parm['productId'],$parm['specificationId'],$parm['number'][$key],$parm['freeze'],$value))
				->execute();
		}

	}

	public function delete($parm){

		DB::delete('sysproductstoresku')->where('productId','=',$parm['productId'])->execute();
	}
	public function get($parm){
		$result = DB::select('*,sysSpecification.id as showid')->from('sysSpecification')->join("sysproductexpresssku",'left')->on("sysSpecification.id","=","sysproductexpresssku.specificationId")->where("sysSpecification.productId","=",$parm['id'])->execute()->as_array();
		return $result;
	}

	public function getStoreInfoAndStoreSku($parm){
		$result = DB::select('sysproductstoresku.number,sysproductstoresku.specificationId,citychina.name as city,syschina.name as province,sysproductstoresku.storeId')->from('sysproductstoresku')->join("sysstore")->on("sysstore.id","=","sysproductstoresku.storeId")->join("syschina")->on("syschina.id","=","sysstore.province")
			->join("syschina as citychina")->on("citychina.id","=","sysstore.city")
			->where("sysproductstoresku.productId","=",$parm['productId'])->execute()->as_array();
		return $result;

	}



}